﻿#ifndef CameraIK_H
#define CameraIK_H

#include "CameraBase.h"
#include <IKapC.h>

class CameraIk : public CameraBase
{
public:
    CameraIk();
    virtual ~CameraIk();
    // Camera interface
public slots:
    virtual void initialize()override;
    virtual void openCamera()override;
    virtual void startGrabbing()override;
    virtual void stopGrabbing()override;
    virtual void closeCamera()override;
    virtual void releaseCamera() override;
    virtual void preProcessImage(const ImageInfo& imgInfo)override;

    virtual QStringList enumCameraList()override;

    virtual void triggerSoftware()override;//软触发
    virtual void setFrameTriggerMode(const QString& camName, const CameraTriggerType &type)override;
    virtual void setFrameTriggerDelay(const QString& camName, const float &delay)override;
    virtual void setLineTriggerMode(const QString& camName, const CameraTriggerType &type)override;

    //ROI
    virtual void setWidth(const QString& camName, const int& width)override;
    virtual void setHeight(const QString& camName, const int& height)override;
    virtual void setOffsetX(const QString& camName, const int& off_x)override;
    //Brightness
    virtual void setExposureTime(const QString& camName, const float &exp)override;
    virtual void setGain(const QString& camName, const float &exp)override;

    //分倍频
    virtual void setMul(const QString& camName, const int& mul) override;
    virtual void setPostDiv(const QString& camName, const int& postDiv) override;

    virtual int getPixelFormat() override;
    virtual bool isColor(int pixelFormat) override;

    virtual int getScanType() override;
    virtual bool isLineScan(int scanType) override;

    //trigger
    virtual CameraTriggerType getFrameTriggerMode(const QString& camName) override;
    virtual FloatValue getFrameTriggerDelay(const QString& camName) override;
    virtual CameraTriggerType getLineTriggerMode(const QString& camName) override;
    //ROI
    virtual IntValue getWidth(const QString& camName) override;
    virtual IntValue getHeight(const QString& camName) override;
    virtual IntValue getOffsetX(const QString& camName) override;

    //Brightness
    virtual FloatValue getExposureTime(const QString& camName) override;
    virtual FloatValue getGain(const QString& camName) override;

    //分倍频
    virtual IntValue getMul(const QString& camName) override;
    virtual IntValue getPostDiv(const QString& camName) override;



    //general
    void setValueBool(const char* strKey, bool bValue);
    void setValueEnum(const char* strKey, unsigned int value);
    void setValueEnumByStr(const char* strKey, const char* value);
    void setValueInt32(const char* strKey, int32_t iValue);
    void setValueInt64(const char* strKey, int64_t iValue);
    void setValueDouble(const char* strKey, double iValue);
    void setValueStr(const char* strKey, QString iValue);
    void setCommand(const char* strKey);

    bool getValueBool(const char* strKey);
    unsigned int getValueEnum(const char* strKey);
    QString getValueEnumStr(const char* strKey);
    IntValue getValueInt32(const char* strKey);
    IntValue getValueInt64(const char* strKey);
    FloatValue getValueDouble(const char* strKey);
    QString getValueStr(const char* strKey);

    static void __stdcall imageCallBackEx(uint32_t eventType, void *pContext);
    static void __stdcall removeCallback(void *context, ITKEVENTINFO eventInfo);


private:
    void saveParamToUserSet();
    void createStreamAndBuffer();
    void configureStream();

private:
    ITKDEVICE m_handle = NULL;
    ITKSTREAM m_hStream = NULL;
    int mIndex = -1;
    ITKBUFFER m_buffer;
    unsigned char *m_bufferData = NULL;
    unsigned int m_payLoadSize = 0;
    unsigned int m_nTLayerType = 0;//设备类型 GIGE or USB
};

#endif // CameraIK_H
